from cmath import inf
import numpy as np
min_money = +inf
min_result = np.random.randint(1,7,5)
n=50000 #蒙特卡洛模拟的次数
M=np.matrix([[18,39,29,48,59],[24,45,23,54,44],[22,45,23,53,53],[28,47,17,57,47],[24,42,24,47,59],[27,48,20,55,53]])
#输入矩阵。
# 一定要注意，python的矩阵输入是真滴麻烦，一定要“小括号加中括号，每一行再用一个中括号”，不然报错报的怀疑人生
yunfei = np.matrix([[10,15,15,10,10,15]])
for k in range(1,n):
    result = np.random.randint(1,7,5);
    index = list(set(result));
    index=np.matrix(index)
    leg=np.size(index)
    A=np.zeros([1,leg])
    A=np.matrix(A)
    for l in range(1,np.size(index)+1):#一定要注意！在python里面区间默认都是左闭右开！所以要+1
        A[0,l-1] = yunfei[0,index[0,l-1]-1]
    money = np.sum(A)
    for i in range(1,6):
        money = money + M[result[i-1]-1,i-1]
    if money < min_money:
        min_money=money
        min_result = result

print('最少花费的费用为：',min_money)
print('对应方案为：',min_result)




